﻿using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Security.Claims;

namespace YiShop.Framework
{
    public static class App
    {
        public static IServiceProvider RootServices { get; set; } = null!;

        /// <summary>
        /// 获取请求上下文
        /// </summary>
        public static HttpContext? HttpContext => RootServices?.GetService<IHttpContextAccessor>()?.HttpContext;

        /// <summary>
        /// 获取请求生存周期的服务
        /// </summary>
        /// <typeparam name="TService"></typeparam>
        /// <returns></returns>
        public static TService? GetService<TService>()
            where TService : class
        {
            return RootServices?.GetService(typeof(TService)) as TService;
        }

    }
}
